/*
This is an example snippet - you should consider tailoring it
to your service.
*/

async function fetchGraphQL(operationsDoc, operationName, variables) {
    const result = await fetch(
        "https://green-feather-500201.ap-south-1.aws.cloud.dgraph.io/graphql",
        {
            method: "POST",
            headers: {
                "Content-Type": "application/json",
                "X-Auth-Token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOiJzL3Byb3h5IiwiZHVpZCI6IjB4NzNmYzllNWEiLCJleHAiOjE2NzAxNzkwOTUsImlzcyI6InMvYXBpIn0.Ly37-FOAuwaQJSJQOtQi-D_uJEvX-7QXJ8xDYHQvny4"
            },
            body: JSON.stringify({
                query: operationsDoc,
                variables: variables,
                operationName: operationName
            })
        }
    );

    return await result.json();
}

const operationsDoc = `
  # Consider giving this query a unique, descriptive
  # name in your application as a best practice
  query unnamedQuery1 {
    queryTask {
      completed
      title
      id
    }
  }
`;

function fetchUnnamedQuery1() {
    return fetchGraphQL(
        operationsDoc,
        "unnamedQuery1",
        {}
    );
}

 async function startFetchUnnamedQuery() {
    const { errors, data } = await fetchUnnamedQuery1();

    if (errors) {
        // handle those errors like a pro
        console.error(errors);
    }

    // do something great with this precious data
    //  console.log(data);
     return data.queryTask
}

export default startFetchUnnamedQuery;